Skip to contentMethod: getCommonPropertyType(ELContext, Object)
1: /*
2: * Copyright (c) 2012, 2021 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.el;
19:
20: import java.beans.FeatureDescriptor;
21: import java.util.Iterator;
22:
23: /**
24: * A convenient class for writing an ELResolver to do custom type conversions.
25: *
26: * <p>
27: * For example, to convert a String to an instance of MyDate, one can write
28: *
29: * <pre>
30: * <code>
31: * ELProcessor elp = new ELProcessor();
32: * elp.getELManager().addELResolver(new TypeConverter() {
33: * Object convertToType(ELContext context, Object obj, Class<?> type) {
34: * if ((obj instanceof String) && type == MyDate.class) {
35: * context.setPropertyResolved(obj, type);
36: * return (obj == null)? null: new MyDate(obj.toString());
37: * }
38: * return null;
39: * }
40: * };
41: * </code>
42: * </pre>
43: *
44: * @since Jakarta Expression Language 3.0
45: */
46: public abstract class TypeConverter extends ELResolver {
47:
48: @Override
49: public Object getValue(ELContext context, Object base, Object property) {
50: return null;
51: }
52:
53: @Override
54: public Class<?> getType(ELContext context, Object base, Object property) {
55: return null;
56: }
57:
58: @Override
59: public void setValue(ELContext context, Object base, Object property, Object value) {
60: }
61:
62: @Override
63: public boolean isReadOnly(ELContext context, Object base, Object property) {
64: return false;
65: }
66:
67: @Deprecated(forRemoval = true, since = "5.0")
68: @Override
69: public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
70: return null;
71: }
72:
73: @Override
74: public Class<?> getCommonPropertyType(ELContext context, Object base) {
75: return null;
76: }
77:
78: /**
79: * Converts an object to a specific type.
80: *
81: * <p>
82: * An <code>ELException</code> is thrown if an error occurs during the conversion.
83: * </p>
84: *
85: * @param context The context of this evaluation.
86: * @param obj The object to convert.
87: * @param targetType The target type for the conversion.
88: * @throws ELException thrown if errors occur.
89: */
90: @Override
91: abstract public <T> T convertToType(ELContext context, Object obj, Class<T> targetType);
92: }